var searchObj={
	inits:function(){
		this.searchFun();
		this.DaohangFun();
		this.DetailsFun();
	},
	Interface:{
		goodsSearch:"http://ww.yc630.com/api/index.php/Buyer/Goods/goodsSearch",  //商品列表
		hotsellRecommend:"http://ww.yc630.com/api/index.php/Buyer/Goods/hotsellRecommend"     //热卖商品
	},
	searchFun:function(){
		var searchtype= common.Geturl().searchtype;
		var searchkey= unescape(common.Geturl().searchkey);
		$("#SearchPosition").html(searchkey)
		common.ajaxFun(searchObj.Interface.goodsSearch,"POST",{searchtype:searchtype,token:token,searchkey:searchkey},searchObj.goodsSearchFun);   //商品
	},
	goodsSearchFun:function(res){
		var str="";
		if (res.code==1) {
			$("#sortNav").hide();
			$("#NoSearch").show();
			$("#NoSearch span").html(unescape(common.Geturl().searchkey));
		common.ajaxFun(searchObj.Interface.hotsellRecommend,"POST",{token:token},searchObj.hotsellRecommendFun);   //热卖商品

		}else if (res.code==0){
			
		$("#sortNav").show();
		$("#NoSearch").hide();
		
			$.each(res.data,function(i,v){
				if (typeof v=="object") {
					str+='<li goods_style='+v.goods_style+' goods_id='+v.goods_id+'>'+
						'<div class="imgBox" people_style='+v.people_style+'><img src='+v.image+' alt=""></div>'+
						'<div class="prices">¥'+v.min_price+'</div>'+
						'<div class="introduce" goods_style='+v.goods_style+' goods_id='+v.goods_id+'>'+v.goods_name+'</div>'+
						'<div class="company" seller_id='+v.seller_id+' brand='+v.brand+'>'+v.seller_name+'</div>'+
						'<div class="productionAddress" prodaddress='+v.prodaddress+'>'+v.shipaddress_name+'</div>'+
					'</li>';
				}
			});
		};
		$("#clothesMain ul").html(str);
	},
	hotsellRecommendFun:function(res){
		//console.log(res.data.count);
		var str2="";

		$.each(res.data,function(i,v){
			if (typeof v=="object") {
				str2+='<li goods_style='+v.goods_style+' goods_id='+v.goods_id+'>'+
					'<div class="imgBox" people_style='+v.people_style+'><img src='+v.image+' alt=""></div>'+
					'<div class="prices">¥'+v.min_price+'</div>'+
					'<div class="introduce">'+v.goods_name+'</div>'+
					'<div class="company" seller_id='+v.seller_id+' brand='+v.brand+'>'+v.seller_name+'</div>'+
					'<div class="productionAddress" prodaddress='+v.prodaddress+'>'+v.shipaddress_name+'</div>'+
				'</li>';
			};
			
		});
		$("#clothesMain ul").html(str2);
	},
	DetailsFun:function(){
		$("#clothesMain").on("click","li",function(){
			var goods_id=$(this).attr("goods_id");
			window.location.href="../page/CommodityDetails.html?goods_id="+goods_id;
		})
	},
	DaohangFun:function(res){
		
		var brandsStr="",goodstyleStr="",peopletypeStr="",prodaddressStr="",DisplayOptionsStr="",goodsListObj={},flag=1;
		goodsListObj.people_style=common.Geturl().people_style;
		goodsListObj.token=token;
		goodsListObj.ordercloum=$("#sortNav li").eq(0).attr("attrC");
		goodsListObj.searchtype= common.Geturl().searchtype;
		goodsListObj.searchkey= unescape(common.Geturl().searchkey);
		$(".peopletype").show();
		$(".peopletype span").eq(0).text(unescape(common.Geturl().people_style_Name));
		
		
		$("#sortNav").on("click","li.lis",function(){
			$(this).addClass("on").siblings("li").removeClass("on");
			goodsListObj.ordercloum=$(this).attr("attrc");
			if (goodsListObj.ordercloum==4) {
				if (flag==1) {
					$(".price").addClass("priceUp").removeClass("priceDown");
					flag=0;
					goodsListObj.ordertype="desc";
				}else if (flag==0) {
					$(".price").addClass("priceDown").removeClass("priceUp");
					flag=1;
					goodsListObj.ordertype="asc";
				};
				
			};
		common.ajaxFun(searchObj.Interface.goodsSearch,"POST",goodsListObj,searchObj.goodsSearchFun);   //产地

		});
		$("#region1 p").click(function(){
			$("#regionList1").show();
			$("#provinceList1").hide();
			$(this).addClass("open");
		})
		$("#province1 p").click(function(){
			common.ajaxFun(commonFunObj.Interface.getProvince,"POST",{},function(res){
				var strProv="",v;
				$.each(res.data,function(k,v){
					strProv+="<div id="+k+">"+v+"</div>";
				})
				$("#provinceList1").html(strProv);
					$("#provinceList1").show();
					$("#regionList1").hide();
					$(this).addClass("open");
				
				});
			}); 
				$("#provinceList1").on("click","div",function(){
					va=$(this).attr("id");
					goodsListObj.province=va;
					$("#region1 p").html("请选择市").addClass("open");
					$("#province1 p").attr("value",va);
					$("#province1 p").html($(this).text()).removeClass("open");
					
					$(this).addClass("on").siblings("div").removeClass("on");
					$("#provinceList1").hide();
		common.ajaxFun(searchObj.Interface.goodsSearch,"POST",goodsListObj,searchObj.goodsSearchFun);   //省份

					common.ajaxFun(commonFunObj.Interface.getCity,"POST",{provinceid:va},function(res){
						$("#regionList1").show();
						var strCity="",v;
							$.each(res.data,function(k,v){
								strCity+="<div id="+k+">"+v+"</div>";
							});
							$("#regionList1").html(strCity);
						}); 
				});
				$("#regionList1").on("click","div",function(){
					$("#region1 p").html($(this).text()).removeClass("open");
					$("#region1 p").attr("value",$(this).attr("id"));
					goodsListObj.city=$(this).attr("id");
					$("#regionList1").hide();
					$(this).addClass("on").siblings("div").removeClass("on");
		common.ajaxFun(searchObj.Interface.goodsSearch,"POST",goodsListObj,searchObj.goodsSearchFun);      //城市

				})
			
		
	}
}
searchObj.inits()